import os

# 设置代理
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"

# 设置本地缓存目录
cache_dir = os.path.join('D:', os.path.sep, 'ModelSpace', 'Cache')
os.environ['HF_HOME'] = cache_dir

from transformers import pipeline

# 创建Pipeline任务
nlp = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")

# 执行文本分类任务
if __name__ == "__main__":
    result = nlp("I like Transformers.")
    print(result)  # 输出：[{'label': 'POSITIVE', 'score': 0.9973547458648682}]

    result = nlp("I don't like overtime.")
    print(result)  # 输出：[{'label': 'NEGATIVE', 'score': 0.9958478212356567}]
